package monitor_sender

import (
	"fmt"
	"fsdvgw/repo"
)

var stopChan chan byte
var eventChan chan *repo.DeviceEvent

func Start() {
	stopChan = make(chan byte)
	eventChan = make(chan *repo.DeviceEvent)
	go sendToDas(stopChan)
	go repo.LaunchMonitor(stopChan, eventChan)

}

func Stop() {
	stopChan <- 1
	stopChan <- 2
}

func sendToDas(stopCh <-chan byte) {
	for {
		select {
		case event := <-eventChan:
			fmt.Println(event)
			// todo 以设备主键ID发送事件给das，目前只有上下线事件
		case <-stopCh:
			return
		}
	}

}
